package com.hjj.appdata;

import com.hjj.beans.ClassRoom;
import com.hjj.beans.Stu;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;


public class MyApp1 {
    public static void main(String[] args) {
        ClassRoom sz2208 = new ClassRoom(1000, "sz2208");
        Stu stu = new Stu(3000, "hjj", 98, sz2208);

        String path = "F:\\IO\\stu3.data";


        try {
            FileOutputStream fileOutputStream = new FileOutputStream(path);
            // 过滤流
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);

            // 如果对象所在类没有序列化，则操作对象流会报错
            // 序列化是指把对象的内容【属性的结果数据进行流化】
            // java.io.NotSerializableException: com.hjj.beans.Stu
            objectOutputStream.writeObject(stu);


            objectOutputStream.flush();

            // 关闭流
            objectOutputStream.close();
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
